package com.liyiruo.tx.service.main13;

import com.liyiruo.tx.mapper.TableAMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 如果我们把testB的传播类型改为REQUIRED，结果也就变成了：没有数据存储成功。
 * 就算在调用方catch了异常，整个事务还是会回滚，因为，调用方和被调方共用的同一个事务
 *
 * @author liyiruo
 * @Description
 * @Date 2022/2/18 下午5:11
 */
@Service
public class TestMain13 {

    @Autowired
    private TableAMapper tableAMapper;
    @Autowired
    private TestBe testBe13;

    @Transactional(propagation = Propagation.REQUIRED)
    public void testMain() {
        tableAMapper.addTableA();  //调用A入参a1
        try {
            testBe13.testB();    //调用testB
        } catch (Exception e) {
            System.out.println("=================");
        }
        tableAMapper.addTableA();  //调用A入参a1
    }
}
